package com.qianfeng.day1029;

import com.dangdang.ddframe.job.config.JobCoreConfiguration;
import com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration;
import com.dangdang.ddframe.job.lite.config.LiteJobConfiguration;
import com.dangdang.ddframe.job.lite.spring.api.SpringJobScheduler;
import com.dangdang.ddframe.job.reg.base.CoordinatorRegistryCenter;
import com.dangdang.ddframe.job.reg.zookeeper.ZookeeperConfiguration;
import com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter;
import com.qianfeng.day1029.job.MyEsJob;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.redisson.Redisson;
import org.redisson.config.Config;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@EnableEurekaClient
public class Day1029Application {

    public static void main(String[] args) {
        SpringApplication.run(Day1029Application.class, args);
    }


    @Bean
    public Redisson getRedisson(){

        Config config = new Config();
        config.useSingleServer().setAddress("redis://192.168.75.135:6379").setPassword("root").setDatabase(0);
        return (Redisson)Redisson.create(config);
    }

    @Bean
    public CoordinatorRegistryCenter center(){

        ZookeeperConfiguration zookeeperConfiguration = new ZookeeperConfiguration("192.168.75.135:2181,192.168.75.135:2182,192.168.75.135:2183", "aaa");
        zookeeperConfiguration.setMaxRetries(4);
        zookeeperConfiguration.setConnectionTimeoutMilliseconds(10000);

        CoordinatorRegistryCenter regCenter = new ZookeeperRegistryCenter(
                zookeeperConfiguration);
        regCenter.init();



        return regCenter;
    }




    @Bean
    public CuratorFramework getLock(){

        ExponentialBackoffRetry retry = new ExponentialBackoffRetry(3000, 3);

        CuratorFramework cf = CuratorFrameworkFactory.builder().retryPolicy(retry).connectString(
                "192.168.75.135:2181,192.168.75.135:2182,192.168.75.135:2183"
        ).build();
        cf.start();

        return cf;
    }


}
